#pragma once
#include <cmath>

namespace ECS
{
	template <typename T>
	struct Vec2
	{
	public:
		T x;
		T y;

		Vec2() : x((T)0), y((T)0) {}
		Vec2(T _x, T _y) : x(_x), y(_y) {}

		template <typename V>
		Vec2( const Vec2<V>& v) : x(static_cast<T>(v.x)), y(static_cast<T>(v.y)) {}

		Vec2<T> operator + (const Vec2<T>& other) const {return Vec2<T>(x + other.x, y + other.y); }
		Vec2<T> operator - (const Vec2<T>& other) const {return Vec2<T>(x - other.x, y - other.y); }
		template <typename M>
		Vec2<T> operator * (M a) const { return Vec2<T>(static_cast<T>(x * a), static_cast<T>(y * a)); }

		bool operator == (const Vec2<T>& other) const {return x == other.x && y == other.y;}
		bool operator != (const Vec2<T>& other) const {return x != other.x || y != other.y;}

		T magnitude() const
		{
			return sqrt(x * x + y * y);
		}
		T magnitudeSq() const
		{
			return x * x + y * y;
		}

		Vec2<T> normalized() const
		{
			T m = magnitude();
			return Vec2<T>(x / m, y / m);
		}
	};
}